package cc.shimeng.fucloud.tools;

import cc.shimeng.fucloud.entity.Classes;
import cc.shimeng.fucloud.repository.ClassesRepository;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ClassesTool {

    @Autowired
    private ClassesRepository repository;

    @Tool(description = "获取所有班级信息", name = "classesGetAll")
    public List<Classes> getAll() {
        return repository.findAll();
    }

    @Tool(description = "获取班级信息", name = "classesGet")
    public Classes get(@ToolParam(description = "班级名称") String name) {
        return repository.findByName(name).stream().findFirst().orElse(null);
    }

    @Tool(description = "创建班级信息", name = "classesSave")
    public Classes save(Classes classes) {
        return repository.save(classes);
    }

    @Tool(description = "删除班级信息", name = "classesDelete")
    public void delete(Integer id) {
        repository.deleteById(id);
    }
}